package com.xposed.aliproxy.xposed.utils;

import android.content.Context;
import android.content.Intent;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.xposed.aliproxy.db.AliTradeModel;
import com.xposed.aliproxy.qrcode.GlobalInstance;
import com.xposed.aliproxy.utils.ActionUtil;
import com.xposed.aliproxy.utils.XposeUtil;

import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class XMerTradeDetailRequestCallBack extends RequestCallBack<String> {
    private Context context;
    private String name;
    private String tradeNo;

    @Override
    public void onFailure(HttpException httpException, String str) {
    }

    public XMerTradeDetailRequestCallBack(Context context, String str, String str2) {
        this.context = context;
        this.tradeNo = str;
        this.name = str2;
    }

    @Override
    public void onSuccess(ResponseInfo<String> responseInfo) {
        try {
            String str = "";
            String str2 = "";
            String str3 = "";
            String str4 = "";
            Elements elementsByClass = Jsoup.parse((String) responseInfo.result).getElementsByClass("trade-info-value");
            if (elementsByClass.size() >= 4) {
                str2 = ((Element) elementsByClass.get(1)).ownText();
                str3 = ((Element) elementsByClass.get(2)).ownText();
                str4 = ((Element) elementsByClass.get(3)).ownText();
            }
            if (elementsByClass.size() >= 8) {
                str = ((Element) elementsByClass.get(7)).ownText();
            }
            String trim = str3.replaceAll("元", "").replaceAll(",", "").trim();
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("date", str2);
            jSONObject.put("money", trim);
            jSONObject.put("remark", str4);
            jSONObject.put("outAliId", str);
            jSONObject.put("tradeNo", this.tradeNo);
            jSONObject.put("name", this.name);
            XposeUtil.xposedLog("tradeDetail->", jSONObject.toString());
//            Serializable aliTradeModel = new AliTradeModel();
            AliTradeModel aliTradeModel = new AliTradeModel();  // TODO 改
            aliTradeModel.setDate(str2);
            aliTradeModel.setAmount(trim);
            aliTradeModel.setRemark(str4);
            aliTradeModel.setOutAliId(str);
            aliTradeModel.setTradeNo(this.tradeNo);
            aliTradeModel.setName(this.name);
            aliTradeModel.setAliBalance(GlobalInstance.getInstance().f1769h);
            aliTradeModel.setType("1");
            aliTradeModel.setStatus("0");
            Intent intent = new Intent(ActionUtil.RECEIVER_TRADE_MODEL);
            intent.putExtra("aliTradeModel", aliTradeModel);
            intent.putExtra("isMer", true);
            this.context.sendBroadcast(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
